<template>
  <div class="navbar">
    <div class="logo" @click="$router.push('/')">
      <img src="@/assets/mylogo.png">
    </div>
    <div><p>
      请输入搜索内容
      <van-icon class="ipt-icon" name="search" />
    </p></div>
    <div>
      <img :src="imgUrl" @click="$router.push('/userinfo')" v-if="imgUrl">
      <img src="@/assets/head.png" @click="$router.push('/login')" v-else>
      <p>下载App</p>
    </div>
  </div>
</template>

<script>
export default {
  name: "Navbar",
  data(){
    return{
      imgUrl:''
    }
  },
  methods:{
    async getdata() {
      if(localStorage.getItem('token')) {
        const res = await this.$http.get('/user/' + localStorage.getItem('id'))
        this.imgUrl = res.data[0].user_img
      }
    }
  },
  created() {
    this.getdata()
  }
}
</script>

<style scoped lang="less">
.navbar{
  display: flex;
  height: 12.5vw;
  background-color: white;
}
.logo{
  display: flex;
  justify-content: center;
  align-items: center;
  width: 27.78vw;
  img{
    width: 90%;
  }
}
div:nth-child(2){
  font-size: 13px;
  line-height: 28px;
  flex: 1;
  display: flex;
  margin: 0 5px;
  align-items: center;
  p{
    padding-left: 20px;
    height: 26px;
    width: 95%;
    border-radius: 12px;
    background-color: #f4f4f4;
    position: relative;
    .ipt-icon{
      position: absolute;
      left: 5px;
      top: 50%;
      transform: translate(0,-40%);
    }
  }
}

div:nth-child(3){
  display: flex;
  justify-content: center;
  align-items: center;
  img{
    width: 24px;
    height: 24px;
  }
  p{
    padding: 1.39vw 2.78vw;
    margin: 0 1.39vw;
    background-color: #ff9db5;
    border-radius: 1.11vw;
    color: white;
    font-size: 3.61vw;
  }
}
</style>
